﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="MediaMonitor.Client.Company_Orders"
    MasterPageFile="~/user.master" Theme="default" Title="Company Orders" CodeBehind="company-orders.aspx.cs" %>


<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="Server">
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script src="../rad-scripts/rad.js" type="text/javascript"></script>
        <script type="text/javascript">

            function getOuterHTML(object) {
                var element;
                if (!object) return null;
                element = document.createElement("div");
                element.appendChild(object.cloneNode(true));
                return element.innerHTML;
            }

            function PrintRadGrid() {
                var previewWnd = window.open('about:blank', '', '', false);
                var sh = '<%= ClientScript.GetWebResourceUrl(radGrid.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",radGrid.Skin)) %>';
                var styleStr = "<html><head><title>Media Monitor - Invoice</title><link href = '" + sh + "' rel='stylesheet' type='text/css'></link></head>";
                var htmlcontent = styleStr + "<body>" + getOuterHTML($find('<%= radGrid.ClientID %>').get_element()) + "</body></html>";
                previewWnd.document.open();
                previewWnd.document.write(htmlcontent);
                previewWnd.document.close();
                previewWnd.print();
                previewWnd.close();
            }


            function requestStart(sender, args) {
                if (args.get_eventTarget().indexOf("DownloadPDF") > 0)
                    args.set_enableAjax(false);
            }
        </script>
    </telerik:RadCodeBlock>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Body" runat="Server">
     
     
     <asp:UpdatePanel ID="pnlUpdate" runat="server">
        <ContentTemplate>
        
        
        <table>
            <tr>
                <td>
                    Select User
                </td>
                <td>
                    <asp:DropDownList ID="lstUser" runat="server" /> 
                </td>
            </tr>
            <tr>
                <td>
                    Dates from:
                </td>
                <td>
                    <!--Start Date Control-->
                    <asp:TextBox Width="100" ID="tbDateFrom" runat="server" ValidationGroup="form"> </asp:TextBox>
                    <img alt="Calendar" onclick="setActiveStyleSheet(this, 'blue'); return showCalendar('<%=tbDateFrom.ClientID%>', 'mm/dd/y');"
                        src='<%=Utility.AppPath%>/js/calendar/calendar3.png' style="display: inline;
                        vertical-align: top" />
                    <asp:CustomValidator ID="cvDateStart" runat="server" ClientValidationFunction="checkDate"
                        ValidationGroup="form" ControlToValidate="tbDateFrom" Display="Dynamic" ErrorMessage="Invalid Date in valid From box."
                        Text="invalid"></asp:CustomValidator>
                     <!--End Date Control-->
                    To:
                    <!--Start Date Control-->
                    <asp:TextBox Width="100" ID="tbDateTo" runat="server" ValidationGroup="form"> </asp:TextBox>
                    <img alt="Calendar" onclick="setActiveStyleSheet(this, 'blue'); return showCalendar('<%=tbDateTo.ClientID%>', 'mm/dd/y');"
                        src='<%=Utility.AppPath%>/js/calendar/calendar3.png' style="display: inline;
                        vertical-align: top" />
                    <asp:CustomValidator ID="cvDateEnd" runat="server" ClientValidationFunction="checkDate"
                        ValidationGroup="form" ControlToValidate="tbDateTo" Display="Dynamic" ErrorMessage="Invalid Date in Valid to box."
                        Text="Invalid"></asp:CustomValidator>
                     <!--End Date Control-->
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <asp:ImageButton ID="btnSearch" runat="server" SkinID="Search" ValidationGroup="form"
                        OnClick="btnSearch_Click" />
                </td>
            </tr>
        </table>
        <br />
            <div style="text-align: left; padding-bottom: 5px;">
                <a href="javascript:void();" onclick="PrintRadGrid(); return false;"><b style="color: #336699;">
                    [ Print list ]</b></a>
            </div>
        <telerik:RadGrid ID="radGrid" runat="server" Width="90%" AllowFilteringByColumn="True" AllowPaging="True"
            AllowSorting="True" GridLines="None" Skin="Hay" OnNeedDataSource="radGrid_NeedDataSource"
            AutoGenerateColumns="false" GroupingSettings-CaseSensitive="false" PageSize="20">
            <MasterTableView DataKeyNames="OrderID" ExpandCollapseColumn-Groupable="true" ExpandCollapseColumn-GroupByExpression="ProductCode"
                GroupLoadMode="Client" ShowFooter="true">
                <Columns>
                    <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="OrderID" HeaderText="Order #" />
                    <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="FullName" HeaderText="User" />
                    <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="Username" HeaderText="Login" />
                    <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="OrderDate" HeaderText="Purchase Date"
                        HtmlEncode="false" DataFormatString="{0:MM/dd/yyyy}" />
                    <telerik:GridHyperLinkColumn Text="Invoice" DataNavigateUrlFields="OrderID" DataNavigateUrlFormatString="../users/invoice.aspx?oid={0}" />
                    <telerik:GridBoundColumn DataField="OrderTotal" HeaderText="Total Amount" ItemStyle-HorizontalAlign="Right"
                        DataFormatString="{0:C2}" Aggregate="Sum" FooterAggregateFormatString="{0:c2}"
                        FooterStyle-HorizontalAlign="Right" FooterStyle-Font-Bold="true" />
                </Columns>
                <DetailTables>
                    <telerik:GridTableView AutoGenerateColumns="false" DataKeyNames="ProdVersionCode"
                        Caption="" AllowSorting="true" PageSize="20" DataSourceID="sqlOrdItems" AllowFilteringByColumn="false"
                        ShowFooter="true" ItemStyle-VerticalAlign="Top">
                        <ParentTableRelation>
                            <telerik:GridRelationFields MasterKeyField="OrderID" DetailKeyField="OrderID" />
                        </ParentTableRelation>
                        <ItemStyle />
                        <AlternatingItemStyle />
                        <Columns>
                            <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="ProductCode" HeaderText="Product Code" ItemStyle-Width="70" />
                            <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="ProductName" HeaderText="Product"
                                ItemStyle-Width="150" />
                            <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="ProdVersionCode"
                                HeaderText="Version Code" ItemStyle-Width="70" />
                            <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="ProdVersionName"
                                HeaderText="Version" ItemStyle-Width="150" />
                            <telerik:GridTemplateColumn HeaderText="Full Video">
                                <ItemTemplate>
                                    <a href="javascript:void(0);" onclick="PopupCenter('../sitefiles/video.aspx?pvid=<%#Eval("ProdVersionCode")%>&t=f&odid=<%#Eval("OrderDetailID")%>', '_blank', 350, 280); ">
                                        <span style='color: <%# Utility.ToBool(Eval("FullVideo")    )==true ? "green" : "red"%>;'>
                                            View </span></a>- <a href="../videos/<%#Eval("ProductCode")%>/<%#Eval("FullVideoFile")%>">
                                                Download</a>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn DataField="Price" HeaderText="Price" ItemStyle-HorizontalAlign="Right"
                                DataFormatString="{0:C2}" Aggregate="Sum" FooterAggregateFormatString="{0:c2}"
                                FooterStyle-HorizontalAlign="Right" FooterStyle-Font-Bold="true" />
                            
                        </Columns>
                    </telerik:GridTableView>
                </DetailTables>
            </MasterTableView>
            <ClientSettings>
                <Scrolling AllowScroll="false" />
                <ClientEvents OnFilterMenuShowing="filterMenuShowing" />
            </ClientSettings>
            <FilterMenu OnClientShowing="MenuShowing" />
        </telerik:RadGrid>
        <asp:LinkButton ID="lnkHidden" runat="server" Text=""></asp:LinkButton>
  
        </ContentTemplate>
     </asp:UpdatePanel>


    <asp:SqlDataSource ID="sqlOrdItems" runat="server" ConnectionString="<%$ ConnectionStrings:DBAdex %>"
        SelectCommand="SELECT * FROM OrderDetail WHERE OrderID = @OrderID">
        <SelectParameters>
            <asp:Parameter Name="OrderID" DefaultValue="0" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
</asp:Content>
